package view.kasse;

import control.SalgsController;
import model.EventSalg;
import utility.PriceFormater;

/**
 *
 * @author Maja Gliese
 */
public class KasseEventListePanel extends javax.swing.JPanel {

    private final KassePanel kassePanel;
    private final EventSalg eventSalg;

    /**
     * Opretter et nyt KasseEventListePanel
     * @param kassePanel
     * @param eventSalg 
     */
    public KasseEventListePanel(KassePanel kassePanel, EventSalg eventSalg) {
        initComponents();
        this.kassePanel = kassePanel;
        this.eventSalg = eventSalg;
        setSize(430, 40);
        setLabels();
    }

    /**
     * Sætter KasseEventListePanelet med Eventsalgets data
     */
    public void setLabels() {
        eventTypeLbl.setText(eventSalg.getEvent().getEventType().getNavn());
        antalBestilteLbl.setText(eventSalg.getEvent().getAntalBestilt() + "");
        antaFremmødteLbl.setText(eventSalg.getEvent().getAntalFremmødte() + "");
        salgsPrisLabel.setText(PriceFormater.formaterPrisTilString(eventSalg.getSalgspris()));
    }

    public EventSalg getEventSalg() {
        return eventSalg;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        fremmødteMenuItem = new javax.swing.JMenuItem();
        rabatKnap = new javax.swing.JMenuItem();
        fjernEventMenuItem = new javax.swing.JMenuItem();
        popUpMenuKnap = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        eventTypeTitelLbl = new javax.swing.JLabel();
        eventTypeLbl = new javax.swing.JLabel();
        antalBestilteTitelLbl = new javax.swing.JLabel();
        antalBestilteLbl = new javax.swing.JLabel();
        antalFremmødtelTitelLbl = new javax.swing.JLabel();
        antaFremmødteLbl = new javax.swing.JLabel();
        prisTitelLabel = new javax.swing.JLabel();
        salgsPrisLabel = new javax.swing.JLabel();
        jSeparator5 = new javax.swing.JSeparator();
        jSeparator7 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator6 = new javax.swing.JSeparator();

        fremmødteMenuItem.setText("Antal fremmødte");
        fremmødteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fremmødteMenuItemActionPerformed(evt);
            }
        });
        jPopupMenu1.add(fremmødteMenuItem);

        rabatKnap.setText("Tilføj Rabat");
        rabatKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rabatKnapActionPerformed(evt);
            }
        });
        jPopupMenu1.add(rabatKnap);

        fjernEventMenuItem.setText("Fjern Event");
        fjernEventMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fjernEventMenuItemActionPerformed(evt);
            }
        });
        jPopupMenu1.add(fjernEventMenuItem);

        setOpaque(false);
        setLayout(null);

        popUpMenuKnap.setBorder(null);
        popUpMenuKnap.setContentAreaFilled(false);
        popUpMenuKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                popUpMenuKnapActionPerformed(evt);
            }
        });
        add(popUpMenuKnap);
        popUpMenuKnap.setBounds(0, 0, 430, 40);

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setOpaque(false);
        jPanel2.setPreferredSize(new java.awt.Dimension(430, 40));
        jPanel2.setLayout(null);

        eventTypeTitelLbl.setText("EventType");
        jPanel2.add(eventTypeTitelLbl);
        eventTypeTitelLbl.setBounds(10, 2, 60, 14);

        eventTypeLbl.setText("EventType");
        jPanel2.add(eventTypeLbl);
        eventTypeLbl.setBounds(10, 19, 190, 17);

        antalBestilteTitelLbl.setText("Antal Bestilte");
        jPanel2.add(antalBestilteTitelLbl);
        antalBestilteTitelLbl.setBounds(215, 2, 70, 14);

        antalBestilteLbl.setText("antalBestilte");
        jPanel2.add(antalBestilteLbl);
        antalBestilteLbl.setBounds(215, 19, 70, 17);

        antalFremmødtelTitelLbl.setText("Fremmødte");
        jPanel2.add(antalFremmødtelTitelLbl);
        antalFremmødtelTitelLbl.setBounds(292, 2, 60, 14);

        antaFremmødteLbl.setText("AntalFremmødte");
        jPanel2.add(antaFremmødteLbl);
        antaFremmødteLbl.setBounds(296, 19, 50, 17);

        prisTitelLabel.setText("Pris");
        jPanel2.add(prisTitelLabel);
        prisTitelLabel.setBounds(353, 2, 70, 14);

        salgsPrisLabel.setText("Pris");
        salgsPrisLabel.setVerifyInputWhenFocusTarget(false);
        jPanel2.add(salgsPrisLabel);
        salgsPrisLabel.setBounds(353, 19, 70, 17);

        jSeparator5.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator5);
        jSeparator5.setBounds(1, 1, 10, 42);

        jSeparator7.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator7);
        jSeparator7.setBounds(209, 1, 10, 42);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator3);
        jSeparator3.setBounds(291, 1, 10, 42);

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel2.add(jSeparator6);
        jSeparator6.setBounds(347, 1, 20, 42);

        add(jPanel2);
        jPanel2.setBounds(0, 0, 430, 40);
    }// </editor-fold>//GEN-END:initComponents

    private void fjernEventMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fjernEventMenuItemActionPerformed
        SalgsController.getInstance().fjernEventFraSalg(eventSalg);
        kassePanel.opdaterKasseListeOgAktivtSalg();
    }//GEN-LAST:event_fjernEventMenuItemActionPerformed

    private void popUpMenuKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_popUpMenuKnapActionPerformed
        jPopupMenu1.show(this, getMousePosition().x, getMousePosition().y);
    }//GEN-LAST:event_popUpMenuKnapActionPerformed

    private void fremmødteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fremmødteMenuItemActionPerformed
        new AntalFremmoedtePopup(this, eventSalg).setVisible(true);
    }//GEN-LAST:event_fremmødteMenuItemActionPerformed

    private void rabatKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rabatKnapActionPerformed
        kassePanel.visRabatPopUpPanel(eventSalg);
    }//GEN-LAST:event_rabatKnapActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel antaFremmødteLbl;
    private javax.swing.JLabel antalBestilteLbl;
    private javax.swing.JLabel antalBestilteTitelLbl;
    private javax.swing.JLabel antalFremmødtelTitelLbl;
    private javax.swing.JLabel eventTypeLbl;
    private javax.swing.JLabel eventTypeTitelLbl;
    private javax.swing.JMenuItem fjernEventMenuItem;
    private javax.swing.JMenuItem fremmødteMenuItem;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JButton popUpMenuKnap;
    private javax.swing.JLabel prisTitelLabel;
    private javax.swing.JMenuItem rabatKnap;
    private javax.swing.JLabel salgsPrisLabel;
    // End of variables declaration//GEN-END:variables
}
